package com.atlzk.common.utils;

import java.util.UUID;

/**
 * @author nobaby
 */
public class UUIDUtil {


    /**
     * 简单的UUID
     */
    public static String getUUID(){
        return UUID.randomUUID().toString();
    }

    /**
     * 获得指定数目的UUID
     * @param number int 需要获得的UUID数量
     * @return String[] UUID数组
     */
    public String[] getUUID(int number) {
        if (number < 1) {
            return null;
        }
        String[] ss = new String[number];
        for (int i = 0; i < number; i++) {
            ss[i] = getUUID();
        }
        return ss;
    }


    /**
     * 没有横线的 UUID
     */
    public String noLine() {
        String uuid = UUID.randomUUID().toString();
        uuid = uuid.replaceAll("-", "");
        if (uuid.length() > 32) {
            uuid = uuid.substring(0, 32);
        }
        return uuid;
    }

    /**
     *  传递一个32位的UUID，可以可上一个方法连用
     *  返回一和每8位就以 - 隔开的UUID
     */
    public String toProto(String id32) {

        if (id32.length() > 32) {
            id32 = id32.substring(0, 32);
        }

        String one = id32.substring(0, 8);
        String two = id32.substring(8, 12);
        String three = id32.substring(12, 16);
        String four = id32.substring(16, 20);
        String five = id32.substring(20, 32);

        return one + "-" + two + "-" + three + "-" + four + "-" + five;
    }


}
